﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
using System.ComponentModel;
using System.ComponentModel.Design;

using edowork.com.SQL2005;

namespace WebInvoicingsys.basecontrol.sale
{
    public partial class uc_list_salebill : System.Web.UI.UserControl
    {
        public string sabid { get; set; }

        public void bind()
        {
            Execute exec = new Execute(Session["connectionString"].ToString());

            string sql = @"select a.productcode, a.productname, a.productshortname, a.goodsclassname, a.goodsunitname, a.goodsspecname, a.stackname, a.guardname, b.qty, b.remark
                              from  v_product a, sellbilldetail b
                                where a.productcode = b.productcode
                                  and b.sabid='{0}'";

            sql = String.Format(sql, sabid);

            string error_msg = "";

            DataSet ds = exec.ExecSQLQueryDataSet(sql, ref error_msg);

            if ((ds == null) || (ds.Tables.Count <= 0) || (ds.Tables[0].Rows.Count != 1))
            {
                return;
            }


            //绑定菜单
            DataTable dt = new DataTable("List");

            dt.Columns.Add("dgvID");
            dt.Columns.Add("productcode");
            dt.Columns.Add("productname");
            dt.Columns.Add("productshortname");
            dt.Columns.Add("goodsclassname");
            dt.Columns.Add("goodsunitname");
            dt.Columns.Add("goodsspecname");
            dt.Columns.Add("stackname");
            dt.Columns.Add("guardname");
            dt.Columns.Add("qty");
            dt.Columns.Add("remark");


            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                DataRow drnew = dt.NewRow();

                drnew["dgvID"] = (dt.Rows.Count + 1).ToString();
                drnew["productcode"] = dr["productcode"].ToString();
                drnew["productname"] = dr["productname"].ToString();
                drnew["productshortname"] = dr["productshortname"].ToString();
                drnew["goodsclassname"] = dr["goodsclassname"].ToString();
                drnew["goodsunitname"] = dr["goodsunitname"].ToString();
                drnew["goodsspecname"] = dr["goodsspecname"].ToString();
                drnew["stackname"] = dr["stackname"].ToString();
                drnew["guardname"] = dr["guardname"].ToString();
                drnew["qty"] = dr["qty"].ToString();
                drnew["remark"] = dr["remark"].ToString();

                dt.Rows.Add(drnew);
            }

            rplist.DataSource = dt;
            rplist.DataBind();

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ;
            }
        }
    }
}